package com.huawei.esdk.tp.domain.model;

import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;

import com.huawei.esdk.platform.common.SDKErrorCode;
import com.huawei.esdk.platform.common.SDKResult;
import com.huawei.esdk.platform.exception.ProtocolAdapterException;
import com.huawei.esdk.tp.common.ErrInfo;
import com.huawei.esdk.tp.device.terminal.TerminalServiceItf;
import com.huawei.esdk.tp.domain.model.bean.VideoSourcesInfo;

public class StreamOperator
{
    private static final Logger LOGGER = Logger.getLogger(StreamOperator.class);

    private TerminalServiceItf terminalService;

    public SDKErrorCode changeVideoOutSrc(Integer hdOut, Integer videoSrc)
    {
        return terminalService.changeVideoOutSrc(hdOut, videoSrc);
    }

    public SDKResult<Map<Integer, String>> getMainVideoSourceList()
    {
        return terminalService.getMainVideoSourceList();
    }

    public SDKResult<Map<Integer, String>> getSubVideoSourceList()
    {
        SDKResult<Map<Integer, String>> result = null;
        
        try
        {
            result = terminalService.getSubVideoSourceList();
        }
        catch (ProtocolAdapterException e)
        {
            LOGGER.error("", e);
            result = new SDKResult<Map<Integer, String>>();
            result.setErrCode(ErrInfo.SDK_SYSTEM_ERRORCODE);
        }
        return result;
    }

    public void getVideoOutSource()
    {        
    }

    public SDKResult<Integer> isConnectAuxSource()
    {
        SDKResult<Integer> result = null;
        try
        {
            result = terminalService.isConnectAuxSourceAPI();
        }
        catch (ProtocolAdapterException ex)
        {
            LOGGER.error("", ex);
            result = new SDKResult<Integer>();
            result.setErrCode(ErrInfo.SDK_SYSTEM_ERRORCODE);
        }
        return result;
    }

    public SDKResult<Integer> isReceiveRemAuxStrm()
    {
        SDKResult<Integer> result = null;
        try
        {
            result = terminalService.isReceiveRemAuxStrmAPI();
        }
        catch (ProtocolAdapterException ex)
        {
            LOGGER.error("", ex);
            result = new SDKResult<Integer>();
            result.setErrCode(ErrInfo.SDK_SYSTEM_ERRORCODE);
        }
        return result;
    }

    public SDKResult<Integer> isSendAuxStream()
    {
        SDKResult<Integer> result = null;
        try
        {
            result = terminalService.isSendAuxStreamAPI();
        }
        catch (ProtocolAdapterException ex)
        {
            LOGGER.error("", ex);
            result = new SDKResult<Integer>();
            result.setErrCode(ErrInfo.SDK_SYSTEM_ERRORCODE);
        }
        return result;
    }

    public SDKErrorCode setLocalMainAux(List<Integer> localMainSrc,
            Integer localAuxSrc)
    {
        return terminalService.setLocalMainAux(localMainSrc, localAuxSrc);
    }

    /**
     * 开始发送辅流。
     * 
     * @return Result
     */
    public SDKErrorCode startSendAuxStream()
    {
        SDKErrorCode result = terminalService.startSendAuxStream();
        return result;
    }

    /**
     * 停止发送辅流。
     * 
     * @return Result
     */
    public SDKErrorCode stopSendAuxStream()
    {
        SDKErrorCode result = terminalService.stopSendAuxStream();
        result.setErrCode(0);
        
        return result;
    }

    /**
     * 启动录播。
     * 
     * @return Result
     */
    public SDKErrorCode startRecordBroad()
    {
        SDKErrorCode result = terminalService.startRecordBroad();
        return result;
    }
    
    public SDKResult<List<VideoSourcesInfo>> queryVideoOutSrcState()
    {
        return terminalService.queryVideoOutSrcState();
    }

    /**
     * 停止录播。
     * 
     * @return Result
     */
    public SDKErrorCode stopRecordBroad()
    {
        SDKErrorCode result = terminalService.stopRecordBroad();
        return result;
    }

    
    /**
     * 启动直播。
     * 
     * @return Result
     */
    public SDKErrorCode startDirectBroad()
    {
        SDKErrorCode result = terminalService.startDirectBroad();
        return result;
    }

    /**
     * 停止直播。
     * 
     * @return Result
     */
    public SDKErrorCode stopDirectBroad()
    {
        SDKErrorCode result = terminalService.stopDirectBroad();
        return result;
    }
    
    
    
    public TerminalServiceItf getTerminalService()
    {
        return terminalService;
    }

    public void setTerminalService(TerminalServiceItf terminalService)
    {
        this.terminalService = terminalService;
    }
}
